/**
 * Created by walkman on 2017/7/14.
 */

angular.module('WfbPlatformApp')
  .factory('profileService', ['$http', '$q', function ($http, $q) {

    return {

      //修改登录密码
      modifyPassword: function (newLoginPassword) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/modifyLoginPassword',
          data: newLoginPassword
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            else {
              deferred.reject("failed to fetch  data");
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );

        return deferred.promise;//返回承诺
      },

      //设置交易密码
      setTradePassword: function (tradePassword) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/setTradePassword',
          data: tradePassword
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              //请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //修改交易密码
      modifyTradePassword: function (newTradePassword) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/modifyTradePassword',
          data: newTradePassword
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              //请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //获取交易密码绑定情况
      getPayPwdSetInfo: function () {

        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/hasTradePassword',
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //获取钱包绑定情况
      getPacketBindInfo: function () {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/hasBindPacket',
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );

        return deferred.promise;//返回承诺
      },

      //获取手机绑定情况
      getPhoneBindInfo: function () {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/hasBindPhone',
          // data: {
          //   "uuid": "192b7f2de24b4f09b118892fe78a9d35"
          // }
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //绑定手机号码
      bindMobilePhone: function (phoneInfo) {

        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/bindMobilephone',
          data: phoneInfo
        }).then(function success(result) {

            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      }

    };

  }]);
